package com.oa.item.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.annotation.MapperScan;

import com.oa.item.entity.Item;
import com.oa.item.entity.ItemWithBLOBs;

@MapperScan
public interface ItemMapper {
    @Delete({
        "delete from item",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into item (id, item_name, ",
        "item_time, item_money, ",
        "item_head, item_liable, ",
        "item_handlers, item_sec, ",
        "item_whodo, spar, ",
        "item_detail, item_doplan)",
        "values (#{id,jdbcType=INTEGER}, #{itemName,jdbcType=VARCHAR}, ",
        "#{itemTime,jdbcType=VARCHAR}, #{itemMoney,jdbcType=VARCHAR}, ",
        "#{itemHead,jdbcType=VARCHAR}, #{itemLiable,jdbcType=VARCHAR}, ",
        "#{itemHandlers,jdbcType=VARCHAR}, #{itemSec,jdbcType=VARCHAR}, ",
        "#{itemWhodo,jdbcType=VARCHAR}, #{spar,jdbcType=VARCHAR}, ",
        "#{itemDetail,jdbcType=LONGVARCHAR}, #{itemDoplan,jdbcType=LONGVARCHAR})"
    })
    int insert(ItemWithBLOBs record);

    @InsertProvider(type=ItemSqlProvider.class, method="insertSelective")
    int insertSelective(ItemWithBLOBs record);

    @Select({
        "select",
        "id, item_name, item_time, item_money, item_head, item_liable, item_handlers, ",
        "item_sec, item_whodo, spar, item_detail, item_doplan",
        "from item",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="item_name", property="itemName", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_time", property="itemTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_money", property="itemMoney", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_head", property="itemHead", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_liable", property="itemLiable", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_handlers", property="itemHandlers", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_sec", property="itemSec", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_whodo", property="itemWhodo", jdbcType=JdbcType.VARCHAR),
        @Result(column="spar", property="spar", jdbcType=JdbcType.VARCHAR),
        @Result(column="item_detail", property="itemDetail", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="item_doplan", property="itemDoplan", jdbcType=JdbcType.LONGVARCHAR)
    })
    ItemWithBLOBs selectByPrimaryKey(Integer id);
    
    @Select({
        "select",
        "id, item_name",
        "from item"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="item_name", property="itemName", jdbcType=JdbcType.VARCHAR),
    })
    List<Item> selectAllItem();

    @UpdateProvider(type=ItemSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ItemWithBLOBs record);

    @Update({
        "update item",
        "set item_name = #{itemName,jdbcType=VARCHAR},",
          "item_time = #{itemTime,jdbcType=VARCHAR},",
          "item_money = #{itemMoney,jdbcType=VARCHAR},",
          "item_head = #{itemHead,jdbcType=VARCHAR},",
          "item_liable = #{itemLiable,jdbcType=VARCHAR},",
          "item_handlers = #{itemHandlers,jdbcType=VARCHAR},",
          "item_sec = #{itemSec,jdbcType=VARCHAR},",
          "item_whodo = #{itemWhodo,jdbcType=VARCHAR},",
          "spar = #{spar,jdbcType=VARCHAR},",
          "item_detail = #{itemDetail,jdbcType=LONGVARCHAR},",
          "item_doplan = #{itemDoplan,jdbcType=LONGVARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(ItemWithBLOBs record);

    @Update({
        "update item",
        "set item_name = #{itemName,jdbcType=VARCHAR},",
          "item_time = #{itemTime,jdbcType=VARCHAR},",
          "item_money = #{itemMoney,jdbcType=VARCHAR},",
          "item_head = #{itemHead,jdbcType=VARCHAR},",
          "item_liable = #{itemLiable,jdbcType=VARCHAR},",
          "item_handlers = #{itemHandlers,jdbcType=VARCHAR},",
          "item_sec = #{itemSec,jdbcType=VARCHAR},",
          "item_whodo = #{itemWhodo,jdbcType=VARCHAR},",
          "spar = #{spar,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Item record);
}